package com.ai.dao;

import java.sql.SQLException;

import com.ai.dbutil.DBconn;
import com.ai.entity.MemberCard;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class CardDao {
	public int addCard(MemberCard mc) {
		Connection conn = DBconn.getInstance();
		int i = 0;
		String sql = null;
		if(mc.getType().equals("次卡"))
			sql = "insert into mem_card (MEMBER_ID, TYPE, TIMES) values (?,?,?)";
		else
			sql = "insert into mem_card (MEMBER_ID, TYPE, DEADLINE) values (?,?,?)";
		PreparedStatement pstmt;
		try {
	        pstmt = (PreparedStatement) conn.prepareStatement(sql);
	        pstmt.setInt(1, mc.getMemberId());
	        pstmt.setString(2, mc.getType());
	        if(mc.getType().equals("次卡"))
	        	pstmt.setInt(3, mc.getTimes());
	        else 
	        	pstmt.setDate(3, new java.sql.Date(mc.getDeadline().getTime()));
	        i = pstmt.executeUpdate();
	        pstmt.close();
	        conn.close();
	    } catch (SQLException e) {
	        e.printStackTrace();
	    }
	    return i;
		
	}
}
